async function crawlingAsins() {
  let totalHeight = 0;
  let distance = 30;
  let asins = [];

  while(totalHeight + 100 < document.body.scrollHeight) {
    window.scrollTo(0, totalHeight);
    totalHeight += distance;
    await sleep(100);
  }

  asins = [...document.querySelectorAll("#gridItemRoot")].map(e => e.querySelector('.p13n-sc-uncoverable-faceout')).map(div => div == null ? null : div.id);
  return asins;
}

async function run() {
  showOverlay();

  if (document.body.innerText.length < 300) {
    chrome.runtime.sendMessage( { action: 'openUrlAndExecScript', data: 'retry' } );
  }
  else {
    const asins = await crawlingAsins();
    chrome.runtime.sendMessage( { action: 'openUrlAndExecScript', data: asins } );
  }
}

run()
